<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<link rel="stylesheet" type="text/css" href="../../css/aui.css" />
		<style type="text/css">
			.aui-chat .aui-chat-header {
				margin-bottom: 0px;
			}
			.aui-chat .aui-chat-content_img {
				color: #212121;
				font-size: 0.7rem;
				border-radius: 0.2rem;
				min-height: 2rem;
				min-width: 4rem;
				position: relative;
				padding: 0.3rem;
				max-width: 44%;
				word-break: break-all;
				word-wrap: break-word;
			}
			.aui-chat .aui-chat-content_img img {
				max-width: 100%;
				display: inline;
				border-radius: 0.2rem;
			}
			.aui-chat .aui-chat-left .aui-chat-content_img {
				background-color: #ffffff;

				float: left;
				left: 0.5rem;
			}
			.aui-chat .aui-chat-right .aui-chat-content_img {
				background-color: #b3e5fc;

				right: 0.5rem;
				float: right;
			}
			.voice {
				height: 1.3rem;
				line-height: 1.3rem;
				width: 4rem;
				position: relative;
				background-image: url(../res/ChatBox/stop.png);
				background-repeat: no-repeat;
				background-position: 0 -0.1rem;
				background-size: 1.4rem auto;
				padding-left: 1.4rem;
				color: #424242;
			}
			.aui-file-size{
				color:#ACACAC;
				padding-top: 3px;
			}
			.aui-file-name{
				font-size: 14px
			}
			.progress{
				border-bottom:1px solid red;
				position:absolute;
				top:100px;
				left:25px;
				max-width: 90%;
			}
			#tx {
			border-radius: 50%;
			display: inline;
			position: absolute;
			top: 7px;
			left: 3px;
		}
		</style>
	</head>
	<body>
		<header class="aui-bar aui-bar-nav" id="head" >
			<a class="aui-btn aui-pull-left" tapmode onclick="closeWin()"> <span class="aui-iconfont aui-icon-left"></span> </a>
			<div class="aui-title">
				<!-- <img v-image-resize="{src:tx?tx:'../res/tx00.jpg'}" id="tx"/><div>{{zh}}</div>  -->
				<!-- {{zh}} -->
			</div>
		</header>
		<section class="aui-chat" id="msglist">
		</section>
	</body>
	<script type="text/javascript" src="../../script/zepto.min.js"></script>
	<script type="text/javascript" src="../../script/jquery.js"></script>
	<script src="../../script/api.js"></script>
	<script src="../../script/vue.js"></script>
	<script src="../../script/app.js"></script>
	<script src="../../script/common.js"></script>
	<script src="../../script/url.js"></script>



	<script type="text/javascript">

		apiready = function() {
			var html = '';
		 id = api.pageParam.id;
		 tx = api.pageParam.tx;
		 zh = api.pageParam.zh;
		html += '<img src="' + api.pageParam.tx + '" id="tx"/>' + api.pageParam.zh;
		$api.html($api.dom('.aui-title'), html);
		$api.fixStatusBar($api.byId('head'));
		var head_h = $api.offset($api.byId('head')).h;
			var rong = api.require('rongCloud2');
			var UIChatBox = api.require('UIChatBox');
			var fileBrowser = api.require('fileBrowser');
			getLatestMessages(api.pageParam.id, 'PRIVATE');
			UIChatBox.open({
				placeholder : '',
				maxRows : 4,
				emotionPath : 'widget://image/ChatBox/emotion',
				texts : {
					recordBtn : {
						normalTitle : '按住  说话',
						activeTitle : '松开  结束'
					},
					sendBtn : {
						title : '发送'
					}
				},
				styles : {
					inputBar : {
						borderColor : '#ececec',
						bgColor : '#fbfbfb'
					},
					inputBox : {
						borderColor : '#B3B3B3',
						bgColor : '#FFFFFF'
					},
					emotionBtn : {
						normalImg : 'widget://image/ChatBox/face1.png'
					},
					extrasBtn : {
						normalImg : 'widget://image/ChatBox/add1.png'
					},
					keyboardBtn : {
						normalImg : 'widget://image/ChatBox/key1.png'
					},
					speechBtn : {
						normalImg : 'widget://image/ChatBox/rec.png'
					},
					recordBtn : {
						normalBg : '#50b6dc',
						activeBg : '#3FBC7D',
						color : '#FFF',
						size : 16
					},
					indicator : {
						target : 'both',
						color : '#c4c4c4',
						activeColor : '#9e9e9e'
					},
					sendBtn : {
						titleColor : '#ffffff',
						bg : '#12b7f5',
						activeBg : '#1ba1d4',
						titleSize : 14
					}
				},
				extras : {
					titleSize : 16,
					titleColor : '#a3a3a3',
					btns : [{
						title : '相册图片',
						normalImg : 'widget://image/ChatBox/img1.png',
						activeImg : 'widget://image/ChatBox/img2.png'
					}, {
						title : '相机拍照',
						normalImg : 'widget://image/ChatBox/cam1.png',
						activeImg : 'widget://image/ChatBox/cam2.png'
					}, {
						title : '我的文件',
						normalImg : 'widget://image/ChatBox/img3.png',
						activeImg : 'widget://image/ChatBox/img3.png'
					}]
				}
			}, function(ret, err) {
				var eventType = ret.eventType;
				var msg = ret.msg;
				if (eventType == 'clickExtras') {
					if (ret.index == 0) {
						getPicture('library')
						pageDown(300);
					} else if (ret.index == 1) {
						getPicture('camera')
						pageDown(300);
					}else if (ret.index == 2) {
						getfile()
						pageDown(300);
					}
				}
				if (eventType == 'send') {
					if ($api.trimAll(ret.msg) == '') {
						api.toast({
							msg : '不能发送空白消息',
							duration : 1000,
							location : 'center'
						});
					} else {
						// console.log();
						var extra = {
							xm1 : getPrefs('username'),
							xm2 : api.pageParam.zh,
							from_member:getPrefs('member_id'),
							tx1 : getPrefs('portrait'),
							tx2 : api.pageParam.tx
						};
						rong.sendTextMessage({
							conversationType : 'PRIVATE',
							targetId : api.pageParam.id,
							text : msg,
							extra : JSON.stringify(extra)
						}, function(ret, err) {

							if (ret.status == 'prepare') {
								xx = ret.result.message.content.text.replace(reg, function(a, b) {
									return face[a] ? face[a] : a;
								});
							} else if (ret.status == 'success') {
								var html = '';
								html += '<div class="aui-chat-item aui-chat-right">';
								html += '	  <div class="aui-chat-media"><img src="' + getPrefs('portrait') + '" /></div>';
								html += '	  <div class="aui-chat-inner"><div class="aui-chat-name">' + getPrefs('username') + '</div>';
								html += '	       <div class="aui-chat-content">';
								html += '		        <div class="aui-chat-arrow"></div>';
								html += xx;
								html += '               </div>';
								html += '	  </div>';
								html += '</div>';
								$api.append($api.dom('#msglist'), html);
								pageDown(300);
							}
						});
					}
				}
			});
			UIChatBox.addEventListener({
				target : 'inputBar',
				name : 'move'
			}, function(ret, err) {
				if (ret) {
					pageDown(300);
					var h = api.pageParam.h;
					var h1 = api.winHeight - h - ret.inputBarHeight - ret.panelHeight;
					api.setFrameAttr({
						name : 'frame_chat',
						rect : {
							x : 0,
							y : h,
							w : 'auto',
							h : h1
						}
					});
					pageDown(300);
				}
			});
			UIChatBox.addEventListener({
				target : 'recordBtn',
				name : 'press'
			}, function(ret, err) {
				sj1 = new Date().getTime();
				if (ret) {
					var savePath = 'fs://lysd_' + (+new Date()) + '.amr';
					api.startRecord({
						path : savePath
					});
				}
			});
			UIChatBox.addEventListener({
				target : 'recordBtn',
				name : 'press_cancel'
			}, function(ret, err) {
				var sj2 = new Date().getTime() - sj1;
				if (sj2 <= 2000) {
					stopRecord();
					api.toast({
						msg : '语音时间较短，请重新录音',
						duration : 3000,
						location : 'middle'
					});
				} else if (sj2 > 2000) {
					api.stopRecord(function(ret, err) {
						if (ret.duration > 0) {
							var path = ret.path;
							var duration = ret.duration;
							var extra = {
								xm1 : getPrefs('username'),
								xm2 : api.pageParam.zh,
								from_member:getPrefs('member_id'),
								tx1 : getPrefs('portrait'),
								tx2 : api.pageParam.tx
							};
							rong.sendVoiceMessage({
								conversationType : 'PRIVATE',
								targetId : api.pageParam.id,
								voicePath : path,
								duration : duration,
								extra : JSON.stringify(extra)
							}, function(ret, err) {
								if (ret.status == 'prepare') {
									yy = ret.result.message.content.voicePath;
									sj_len = ret.result.message.content.duration;
								} else if (ret.status == 'success') {
									var html = '';

									html += '<div class="aui-chat-item aui-chat-right">';
									html += '	  <div class="aui-chat-media"><img src="' + getPrefs('portrait') + '" /></div>';
									html += '	  <div class="aui-chat-inner"><div class="aui-chat-name">' + getPrefs('member_id') + '</div>';
									html += '	       <div class="aui-chat-content_img">';
									html += '		        <div class="aui-chat-arrow"></div>';
									html += '<div onclick="play(this,\'' + yy + '\')" class="voice"> ' + sj_len + ' "</div>';
									html += '               </div>';
									html += '	  </div>';
									html += '</div>';
									$api.append($api.dom('#msglist'), html);
									pageDown(200);
									api.sendEvent({
										name : 'senthh'
									});
								} else if (ret.status == 'error') {
									api.toast({
										msg : '语音发送失败'
									});
								}
							});
						}
					});
				}
			});
			UIChatBox.addEventListener({
				target : 'recordBtn',
				name : 'move_in'
			}, function(ret, err) {
				sj1 = new Date().getTime();
				if (ret) {
					var savePath = 'fs://lysd_' + (+new Date()) + '.amr';
					api.startRecord({
						path : savePath
					});
				}
			});
			UIChatBox.addEventListener({
				target : 'recordBtn',
				name : 'move_out_cancel'
			}, function(ret, err) {
				var sj2 = new Date().getTime() - sj1;
				if (sj2 <= 2000) {
					stopRecord();
					api.toast({
						msg : '语音时间较短，请重新录音',
						duration : 3000,
						location : 'middle'
					});
				} else if (sj2 > 2000) {
					api.stopRecord(function(ret, err) {
						if (ret.duration > 0) {
							var path = ret.path;
							var duration = ret.duration;
							var extra = {
								xm1 : getPrefs('username'),
								xm2 : api.pageParam.zh,
								from_member:getPrefs('member_id'),
								tx1 : getPrefs('portrait'),
								tx2 : api.pageParam.tx
							};
							rong.sendVoiceMessage({
								conversationType : 'PRIVATE',
								targetId : api.pageParam.id,
								voicePath : path,
								duration : duration,
								extra : JSON.stringify(extra)
							}, function(ret, err) {
								if (ret.status == 'prepare') {
									yy = ret.result.message.content.voicePath;
									sj_len = ret.result.message.content.duration;
								} else if (ret.status == 'success') {
									var html = '';
									html += '<div class="aui-chat-item aui-chat-right">';
									html += '	  <div class="aui-chat-media"><img src="' + getPrefs('portrait') + '" /></div>';
									html += '	  <div class="aui-chat-inner"><div class="aui-chat-name">' + getPrefs('member_id') + '</div>';
									html += '	       <div class="aui-chat-content_img">';
									html += '		        <div class="aui-chat-arrow"></div>';
									html += '<div onclick="play(this,\'' + yy + '\')" class="voice"> ' + sj_len + ' "</div>';
									html += '               </div>';
									html += '	  </div>';
									html += '</div>';
									$api.append($api.dom('#msglist'), html);
									pageDown(200);
									api.sendEvent({
										name : 'senthh'
									});
								} else if (ret.status == 'error') {
									api.toast({
										msg : '语音发送失败'
									});
								}
							});
						}
					});
				}
			});
			api.addEventListener({
				name : 'new_msg'
			}, function(ret, err) {
				var html = '';
				if (ret.value.msg.targetId == api.pageParam.id) {
					if (ret.value.msg.objectName == 'RC:TxtMsg') {
						txt = ret.value.msg.content.text.replace(reg, function(a, b) {
							return face[a] ? face[a] : a;
						});
						var extra = transExtra(ret.value.msg.content.extra);
						html += '<div class="aui-chat-header">' + sj(ret.value.msg.sentTime) + '</div>';
						html += '<div class="aui-chat-item aui-chat-left">';
						html += '	  <div class="aui-chat-media"><img src="' + api.pageParam.tx + '" /></div>';
						html += '	  <div class="aui-chat-inner"><div class="aui-chat-name">' + api.pageParam.zh + '</div>';
						if(extra.mtype==undefined){
							html += '	       <div class="aui-chat-content">';

							html += '		        <div class="aui-chat-arrow"></div>';
							html += txt;
						}else{
							html += '	       <div class="aui-chat-content aui_chat-content-file-receive" onclick="openfile(\'' + extra.fileUrl + '\')">';
							html += '		        <div class="aui-chat-arrow"></div>';

							html +='<img  style="float:left;width:60px"  src="../res/ChatBox/'+checktype(extra.type)+'.png"/>';
							html +='<div style="float:right;margin-left:10px">';
							html +='<div class="aui-file-name">'+getSubStr(extra.name) +'</div>';
							html +='<div class="aui-file-size">'+extra.size+'</div>';
							html +='</div>'
						}
						html += '               </div>';
						html += '	  </div>';
						html += '</div>';
					} else if (ret.value.msg.objectName == 'RC:ImgMsg') {
						html += '<div class="aui-chat-header">' + sj(ret.value.msg.sentTime) + '</div>';
						html += '<div class="aui-chat-item aui-chat-left">';
						html += '	  <div class="aui-chat-media"><img src="' + api.pageParam.tx + '" /></div>';
						html += '	  <div class="aui-chat-inner"><div class="aui-chat-name">' + api.pageParam.zh + '</div>';
						html += '	       <div class="aui-chat-content_img">';
						html += '		        <div class="aui-chat-arrow"></div>';
						html += '               <img onclick="openImage(\'' + ret.value.msg.content.imageUrl + '\')" src="' + ret.value.msg.content.thumbPath + '"/>';
						html += '          </div>';
						html += '	  </div>';
						html += '</div>';
					} else if (ret.value.msg.objectName == 'RC:VcMsg') {
						html += '<div class="aui-chat-header">' + sj(ret.value.msg.sentTime) + '</div>';
						html += '<div class="aui-chat-item aui-chat-left">';
						html += '	  <div class="aui-chat-media"><img src="' + api.pageParam.tx + '" /></div>';
						html += '	  <div class="aui-chat-inner"><div class="aui-chat-name">' + api.pageParam.zh + '</div>';
						html += '	       <div class="aui-chat-content_img">';
						html += '		        <div class="aui-chat-arrow"></div>';
						html += '<div onclick="play(this,\'' + ret.value.msg.content.voicePath + '\')" class="voice"> ' + ret.value.msg.content.duration + ' "</div>';
						html += '          </div>';
						html += '	  </div>';
						html += '</div>';
					}
					$api.append($api.dom('#msglist'), html);
					pageDown(300);
				}
			});
			api.setCustomRefreshHeaderInfo({
				bgColor : '#ffffff',
				image : {
					pull : ['widget://image/1.png', 'widget://image/2.png', 'widget://image/3.png', 'widget://image/4.png', 'widget://image/5.png', 'widget://image/6.png', 'widget://image/7.png', 'widget://image/8.png'],
					load : ['widget://image/8.png', 'widget://image/7.png', 'widget://image/6.png', 'widget://image/5.png', 'widget://image/4.png', 'widget://image/3.png', 'widget://image/2.png', 'widget://image/1.png']
				}
			}, function() {
				getHistoryMessages(api.pageParam.id, 'PRIVATE');
				setTimeout(function() {
					api.refreshHeaderLoadDone();
				}, 3000)
			});
		}
		function getfile(){
			var fileBrowser = api.require('fileBrowser');
			fileBrowser.open(function(ret) {
			    if (ret) {
							uploadFile(ret.url,ret.name,ret.size);
			    }
			});
			fileBrowser.skin({
		    skin:2,
		});
		}
		function bytesToSize(bytes) {
	    if (bytes === 0) return '0 B';
	    var k = 1000, // or 1024
	        sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
	        i = Math.floor(Math.log(bytes) / Math.log(k));
	   	return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
		}
		function uploadFile(path,name,size){
			var file_class= name.substring(0,name.indexOf("."));
			var index = name.lastIndexOf(".");
			var suffix = name.substr(index+1);

			var obj = api.require('qiniuUpfile');
			var baseUrl = 'http://rgsqn.tiaocheng-tech.com/'; //七牛给你的测试域名，也可使用自己捆绑的域名youe.xxx.com
			var html = '';
			html += '<div class="aui-chat-item aui-chat-right">';
			html += '	  <div class="aui-chat-media"><img src="' + getPrefs('portrait') + '" /></div>';
			html += '	  <div class="aui-chat-inner"><div class="aui-chat-name">' + getPrefs('member_id') + '</div>';
			html += '	       <div class="aui-chat-content aui_chat-content-file-send">';
			html +='<img  style="float:left;width:60px"  src="../res/ChatBox/'+checktype(suffix)+'.png"/>';
			html +='<div style="float:right;margin-left:10px">';
			html +='<div class="aui-file-name">'+getSubStr(name)+'</div>';
			html +='<div class="aui-file-size">'+bytesToSize(size)+'</div>';
			html +='</div>'
			html += '               </div>';
			html += '<div class="progress '+file_class+'"></div>'
			html += '	  </div>';
			html += '</div>';

			$api.append($api.dom('#msglist'), html);
			pageDown(300);

				obj.upfile({
				    file: path,
				    name: name
				}, function(ret, err) {
				    if (ret.status) {
				        if (ret.oper == "complete") {
				            //上传成功后组装访问路径，或直接访问文档
										sendFileMessage(qiniuhost + ret.info.key,name,size,file_class);
				            // $api.text(b, baseUrl + ret.info.key);
				        } else if (ret.oper == "progress") {
										$api.css($api.dom("."+file_class), 'width:'+ret.percent+'%');
				        }
				    }
				});
			}
			function sendFileMessage(path,name,size,file_class){
				var index = name.lastIndexOf(".");
				var suffix = name.substr(index+1);
				var extra = {
					xm1 : getPrefs('username'),
					xm2 : api.pageParam.zh,
					from_member:getPrefs('member_id'),
					tx1 : getPrefs('portrait'),
					tx2 : api.pageParam.tx,
					name: name, // 文件名称
					size: bytesToSize(size), // 文件大小，单位自己约定
					type: suffix, // 文件的后缀名，例如 png、js、doc ...
					mtype:'file',
					fileUrl: path // 文件地址
				};
				var rong = api.require('rongCloud2');

				rong.sendTextMessage({
					conversationType : 'PRIVATE',
					targetId : api.pageParam.id,
					text : name,
					extra : JSON.stringify(extra)
				}, function(ret, err) {
					if (ret.status == 'prepare') {
						xx = ret.result.message.content.text.replace(reg, function(a, b) {
							return face[a] ? face[a] : a;
						});
					} else if (ret.status == 'success') {
						$api.css($api.dom("."+file_class), 'width:0px');
					}
				});
				}
		function getPicture(type) {
			api.getPicture({
				sourceType : type,
				encodingType : 'jpg',
				mediaValue : 'pic',
				destinationType : 'url',
				allowEdit : false,
				quality : 100,
				saveToPhotoAlbum : false
			}, function(ret, err) {
				if (ret) {
					var extra = {
						xm1 : getPrefs('member_id'),
						xm2 : api.pageParam.zh,
						from_member:getPrefs('member_id'),
						tx1 : getPrefs('portrait'),
						tx2 : api.pageParam.tx
					};
					var rong = api.require('rongCloud2');
					rong.sendImageMessage({
						conversationType : 'PRIVATE',
						targetId : api.pageParam.id,
						imagePath : ret.data,
						extra : JSON.stringify(extra)
					}, function(ret, err) {
						if (ret.status == 'prepare') {
							var bpic = ret.result.message.content.imageUrl;
							var spic = ret.result.message.content.thumbPath;
							var html = '';
							html += '<div class="aui-chat-item aui-chat-right">';
							html += '	  <div class="aui-chat-media"><img src="' + getPrefs('portrait') + '" /></div>';
							html += '	  <div class="aui-chat-inner"><div class="aui-chat-name">' + getPrefs('member_id') + '</div>';
							html += '	       <div class="aui-chat-content_img">';
							html += '		        <div class="aui-chat-arrow"></div>';
							html += '               <img onclick="openImage(\'' + bpic + '\')" src="' + spic + '"/>';
							html += '          </div>';
							html += '	  </div>';
							html += '</div>';
							$api.append($api.dom('#msglist'), html);
						}
					});
					var UIChatBox = api.require('UIChatBox');
					UIChatBox.closeBoard();
				} else {
					api.toast({
						msg : '图像获取失败',
						duration : 3000,
						location : 'bottom'
					});
					var UIChatBox = api.require('UIChatBox');
					UIChatBox.closeBoard();
				}
			});
		}

		//获取最后一段会话
		function getLatestMessages(targetId, conversationType) {
			// return;
			var rong = api.require('rongCloud2');
			rong.getLatestMessages({
				conversationType : conversationType,
				targetId : targetId,
				count : 4
			}, function(ret, err) {
				// console.log(JSON.stringify(ret.result));
				if (ret.status == 'success') {
					if (ret.result && ret.result.length > 0) {
						var html = '';
						for (var i = ret.result.length - 1; i >= 0; i--) {
							var rs = ret.result[i];
							var extra = transExtra(rs.content.extra);
							if (extra.xm1 == getPrefs('member_id')) {
								var xm = extra.xm2;
								var tx = extra.tx2;
							} else {
								var xm = extra.xm1;
								var tx = extra.tx1;
							}
							if (rs.objectName == 'RC:TxtMsg') {
								jsxx = rs.content.text.replace(reg, function(a, b) {
									return face[a] ? face[a] : a;
								});
								if (rs.messageDirection == 'SEND') {
									html += '<div class="aui-chat-header" data-id="' + rs.messageId + '">' + sj(rs.sentTime) + '</div>';
									html += '<div class="aui-chat-item aui-chat-right">';
									html += '	  <div class="aui-chat-media"><img src="' + getPrefs('portrait') + '" /></div>';
									html += '	  <div class="aui-chat-inner"><div class="aui-chat-name">' + getPrefs('username') + '</div>';
									if(extra.mtype==undefined){
										html += '	       <div class="aui-chat-content">';
										html += '		        <div class="aui-chat-arrow"></div>';
										html += jsxx;
									}else{

										html += '	       <div class="aui-chat-content aui_chat-content-file-send" onclick="openfile(\'' + extra.fileUrl + '\')">';
										html += '		        <div class="aui-chat-arrow"></div>';
										html +='<img  style="float:left;width:60px"  src="../res/ChatBox/'+checktype(extra.type)+'.png"/>';
										html +='<div style="float:right;margin-left:10px">';
										html +='<div class="aui-file-name">'+getSubStr(extra.name)+'</div>';
										html +='<div class="aui-file-size">'+extra.size+'</div>';
										html +='</div>'
									}
									// html += '		        <div class="aui-chat-arrow"></div>';
									// html += jsxx;
									html += '               </div>';
									html += '	  </div>';
									html += '</div>';
								} else {
									html += '<div class="aui-chat-header" data-id="' + rs.messageId + '">' + sj(rs.sentTime) + '</div>';
									html += '<div class="aui-chat-item aui-chat-left">';
									html += '	  <div class="aui-chat-media"><img src="' + tx + '" /></div>';
									html += '	  <div class="aui-chat-inner"><div class="aui-chat-name">' + xm + '</div>';
									if(extra.mtype==undefined){
										html += '	       <div class="aui-chat-content">';

										html += '		        <div class="aui-chat-arrow"></div>';
										html += jsxx;
									}else{
										html += '	       <div class="aui-chat-content aui_chat-content-file-receive" onclick="openfile(\'' + extra.fileUrl + '\')">';
										html += '		        <div class="aui-chat-arrow"></div>';
										html +='<img  style="float:left;width:60px"  src="../res/ChatBox/'+checktype(extra.type)+'.png"/>';
										html +='<div style="float:right;margin-left:10px">';
										html +='<div class="aui-file-name">'+getSubStr(extra.name)+'</div>';
										html +='<div class="aui-file-size">'+extra.size+'</div>';
										html +='</div>'
									}
									// html += '		        <div class="aui-chat-arrow"></div>';
									// html += jsxx;
									html += '               </div>';
									html += '	  </div>';
									html += '</div>';
								}
							} else if (rs.objectName == 'RC:ImgMsg') {
								var bpic = rs.content.imageUrl;
								var spic = rs.content.thumbPath;
								if (rs.messageDirection == 'SEND') {
									html += '<div class="aui-chat-header" data-id="' + rs.messageId + '">' + sj(rs.sentTime) + '</div>';
									html += '<div class="aui-chat-item aui-chat-right">';
									html += '	  <div class="aui-chat-media"><img src="' + getPrefs('portrait') + '" /></div>';
									html += '	  <div class="aui-chat-inner"><div class="aui-chat-name">' + getPrefs('username') + '</div>';
									html += '	       <div class="aui-chat-content_img">';
									html += '		        <div class="aui-chat-arrow"></div>';
									html += '               <img onclick="openImage(\'' + bpic + '\')" src="' + spic + '"/>';
									html += '          </div>';
									html += '	  </div>';
									html += '</div>';
								} else {
									html += '<div class="aui-chat-header" data-id="' + rs.messageId + '">' + sj(rs.sentTime) + '</div>';
									html += '<div class="aui-chat-item aui-chat-left">';
									html += '	  <div class="aui-chat-media"><img src="' + tx + '" /></div>';
									html += '	  <div class="aui-chat-inner"><div class="aui-chat-name">' + xm + '</div>';
									html += '	       <div class="aui-chat-content_img">';
									html += '		        <div class="aui-chat-arrow"></div>';
									html += '               <img onclick="openImage(\'' + bpic + '\')" src="' + spic + '"/>';
									html += '          </div>';
									html += '	  </div>';
									html += '</div>';
								}
							} else if (rs.objectName == 'RC:VcMsg') {
								if (rs.messageDirection == 'SEND') {
									html += '<div class="aui-chat-header" data-id="' + rs.messageId + '">' + sj(rs.sentTime) + '</div>';
									html += '<div class="aui-chat-item aui-chat-right">';
									html += '	  <div class="aui-chat-media"><img src="' + getPrefs('portrait') + '" /></div>';
									html += '	  <div class="aui-chat-inner"><div class="aui-chat-name">' + getPrefs('username') + '</div>';
									html += '	       <div class="aui-chat-content_img">';
									html += '		        <div class="aui-chat-arrow"></div>';
									html += '<div onclick="play(this,\'' + rs.content.voicePath + '\')" class="voice"> ' + rs.content.duration + ' "</div>';
									html += '          </div>';
									html += '	  </div>';
									html += '</div>';
								} else {
									html += '<div class="aui-chat-header" data-id="' + rs.messageId + '">' + sj(rs.sentTime) + '</div>';
									html += '<div class="aui-chat-item aui-chat-left">';
									html += '	  <div class="aui-chat-media"><img src="' + tx + '" /></div>';
									html += '	  <div class="aui-chat-inner"><div class="aui-chat-name">' + xm + '</div>';
									html += '	       <div class="aui-chat-content_img">';
									html += '		        <div class="aui-chat-arrow"></div>';
									html += '<div onclick="play(this,\'' + rs.content.voicePath + '\')" class="voice"> ' + rs.content.duration + ' "</div>';
									html += '          </div>';
									html += '	  </div>';
									html += '</div>';
								}
							}
						}

						$api.html($api.dom('#msglist'), html);
						// pageDown(300);
					}
				}
			})
		}

		//下拉加载历史记录
		function getHistoryMessages(targetId, conversationType) {
			var rong = api.require('rongCloud2');
			var oldid = $(".aui-chat-header").first().data("id");
			rong.getHistoryMessages({
				conversationType : conversationType,
				targetId : targetId,
				oldestMessageId : oldid,
				count : 8
			}, function(ret, err) {
				if (ret.status == 'success') {
					var html = '';
					if (ret.result && ret.result.length > 0) {
						for (var i = ret.result.length - 1; i >= 0; i--) {
							var rs = ret.result[i];
							var extra = transExtra(rs.content.extra);
							if (extra.xm1 == getPrefs('member_id')) {
								var xm = extra.xm2;
								var tx = extra.tx2;
							} else {
								var xm = extra.xm1;
								var tx = extra.tx1;
							}
							if (rs.objectName == 'RC:TxtMsg') {
								jsxx = rs.content.text.replace(reg, function(a, b) {
									return face[a] ? face[a] : a;
								});
								if (rs.messageDirection == 'SEND') {
									html += '<div class="aui-chat-header" data-id="' + rs.messageId + '">' + sj(rs.sentTime) + '</div>';
									html += '<div class="aui-chat-item aui-chat-right">';
									html += '	  <div class="aui-chat-media"><img src="' + getPrefs('portrait') + '" /></div>';
									html += '	  <div class="aui-chat-inner"><div class="aui-chat-name">' + getPrefs('username') + '</div>';
									if(extra.mtype==undefined){
										html += '	       <div class="aui-chat-content">';

										html += '		        <div class="aui-chat-arrow"></div>';
										html += jsxx;
									}else{
										html += '	       <div class="aui-chat-content aui_chat-content-file-send" onclick="openfile(\'' + extra.fileUrl + '\')">';
										html += '		        <div class="aui-chat-arrow"></div>';

										html +='<img  style="float:left;width:60px"  src="../res/ChatBox/'+checktype(extra.type)+'.png"/>';
										html +='<div style="float:right;margin-left:10px">';
										html +='<div class="aui-file-name">'+getSubStr(extra.name)+'</div>';
										html +='<div class="aui-file-size">'+extra.size+'</div>';
										html +='</div>'
									}
									// html += '		        <div class="aui-chat-arrow"></div>';
									// html += jsxx;
									html += '               </div>';
									html += '	  </div>';
									html += '</div>';
								} else {
									html += '<div class="aui-chat-header" data-id="' + rs.messageId + '">' + sj(rs.sentTime) + '</div>';
									html += '<div class="aui-chat-item aui-chat-left">';
									html += '	  <div class="aui-chat-media"><img src="' + tx + '" /></div>';
									html += '	  <div class="aui-chat-inner"><div class="aui-chat-name">' + xm + '</div>';
									if(extra.mtype==undefined){
										html += '	       <div class="aui-chat-content">';

										html += '		        <div class="aui-chat-arrow"></div>';
										html += jsxx;
									}else{
										html += '	       <div class="aui-chat-content aui_chat-content-file-receive" onclick="openfile(\'' + extra.fileUrl + '\')">';
										html += '		        <div class="aui-chat-arrow"></div>';

										html +='<img  style="float:left;width:60px"  src="../res/ChatBox/'+checktype(extra.type)+'.png"/>';
										html +='<div style="float:right;margin-left:10px">';
										html +='<div class="aui-file-name">'+getSubStr(extra.name)+'</div>';
										html +='<div class="aui-file-size">'+extra.size+'</div>';
										html +='</div>'
									}
									// html += '		        <div class="aui-chat-arrow"></div>';
									// html += jsxx;
									html += '               </div>';
									html += '	  </div>';
									html += '</div>';
								}
							} else if (rs.objectName == 'RC:ImgMsg') {
								var bpic = rs.content.imageUrl;
								var spic = rs.content.thumbPath;
								if (rs.messageDirection == 'SEND') {
									html += '<div class="aui-chat-header" data-id="' + rs.messageId + '">' + sj(rs.sentTime) + '</div>';
									html += '<div class="aui-chat-item aui-chat-right">';
									html += '	  <div class="aui-chat-media" ><img src="' + getPrefs('portrait') + '" /></div>';
									html += '	  <div class="aui-chat-inner"><div class="aui-chat-name">' + getPrefs('username') + '</div>';
									html += '	       <div class="aui-chat-content_img">';
									html += '		        <div class="aui-chat-arrow"></div>';
									html += '               <img onclick="openImage(\'' + bpic + '\')" src="' + spic + '"/>';
									html += '          </div>';
									html += '	  </div>';
									html += '</div>';
								} else {
									html += '<div class="aui-chat-header" data-id="' + rs.messageId + '">' + sj(rs.sentTime) + '</div>';
									html += '<div class="aui-chat-item aui-chat-left">';
									html += '	  <div class="aui-chat-media"><img src="' + tx + '" /></div>';
									html += '	  <div class="aui-chat-inner"><div class="aui-chat-name">' + xm + '</div>';
									html += '	       <div class="aui-chat-content_img">';
									html += '		        <div class="aui-chat-arrow"></div>';
									html += '               <img onclick="openImage(\'' + bpic + '\')" src="' + spic + '"/>';
									html += '          </div>';
									html += '	  </div>';
									html += '</div>';
								}
							} else if (rs.objectName == 'RC:VcMsg') {
								if (rs.messageDirection == 'SEND') {
									html += '<div class="aui-chat-header" data-id="' + rs.messageId + '">' + sj(rs.sentTime) + '</div>';
									html += '<div class="aui-chat-item aui-chat-right">';
									html += '	  <div class="aui-chat-media" ><img src="' + getPrefs('portrait') + '" /></div>';
									html += '	  <div class="aui-chat-inner"><div class="aui-chat-name">' + getPrefs('username') + '</div>';
									html += '	       <div class="aui-chat-content_img">';
									html += '		        <div class="aui-chat-arrow"></div>';
									html += '<div onclick="play(this,\'' + rs.content.voicePath + '\')" class="voice"> ' + rs.content.duration + ' "</div>';
									html += '          </div>';
									html += '	  </div>';
									html += '</div>';
								} else {
									html += '<div class="aui-chat-header" data-id="' + rs.messageId + '">' + sj(rs.sentTime) + '</div>';
									html += '<div class="aui-chat-item aui-chat-left">';
									html += '	  <div class="aui-chat-media"><img src="' + tx + '" /></div>';
									html += '	  <div class="aui-chat-inner"><div class="aui-chat-name">' + xm + '</div>';
									html += '	       <div class="aui-chat-content_img">';
									html += '		        <div class="aui-chat-arrow"></div>';
									html += '<div onclick="play(this,\'' + rs.content.voicePath + '\')" class="voice"> ' + rs.content.duration + ' "</div>';
									html += '          </div>';
									html += '	  </div>';
									html += '</div>';
								}
							}
						}
						$api.prepend($api.dom('#msglist'), html);
						api.refreshHeaderLoadDone();
					} else {
						api.toast({
							msg : '木有了消息啦…'
						});
						api.refreshHeaderLoadDone();
					}
				}
			})
		}

		//滑动到底部
		function pageDown(time) {
			setTimeout(function() {
				api.pageDown({
					bottom : true,
					animate : true
				}, function(ret) {
				});
			}, time || 0)
		}

		//终止录音
		function stopRecord() {
			api.stopRecord(function(ret, err) {
			});
		}

		//播放录音
		function play(el, path) {
			$api.css(el, 'background-image:url(../res/ChatBox/playing.gif)');
			api.startPlay({
				path : path
			}, function() {
				$api.css(el, 'background-image:url(../res/ChatBox/stop.png)');
			});
		}

		//表情符号转换
		var reg = /\[.+?\]/g;
		var face = {
			'[微笑]' : '<span><img src="../res/ChatBox/emotion/Expression_1.png"  width="28"/></span>',
			'[撇嘴]' : '<span><img src="../res/ChatBox/emotion/Expression_2.png"  width="28" /></span>',
			'[色]' : '<span><img src="../res/ChatBox/emotion/Expression_3.png"  width="28" /></span>',
			'[发呆]' : '<span><img src="../res/ChatBox/emotion/Expression_4.png"  width="28" /></span>',
			'[得意]' : '<span><img src="../res/ChatBox/emotion/Expression_5.png"  width="28" /></span>',
			'[流泪]' : '<span><img src="../res/ChatBox/emotion/Expression_6.png"  width="28" /></span>',
			'[害羞]' : '<span><img src="../res/ChatBox/emotion/Expression_7.png"  width="28" /></span>',
			'[闭嘴]' : '<span><img src="../res/ChatBox/emotion/Expression_8.png"  width="28" /></span>',
			'[睡]' : '<span><img src="../res/ChatBox/emotion/Expression_9.png"  width="28" /></span>',
			'[大哭]' : '<span><img src="../res/ChatBox/emotion/Expression_10.png"  width="28"/></span>',
			'[尴尬]' : '<span><img src="../res/ChatBox/emotion/Expression_11.png"  width="28"/></span>',
			'[发怒]' : '<span><img src="../res/ChatBox/emotion/Expression_12.png"  width="28"/></span>',
			'[调皮]' : '<span><img src="../res/ChatBox/emotion/Expression_13.png"  width="28" /></span>',
			'[呲牙]' : '<span><img src="../res/ChatBox/emotion/Expression_14.png"  width="28" /></span>',
			'[惊讶]' : '<span><img src="../res/ChatBox/emotion/Expression_15.png"  width="28" /></span>',
			'[难过]' : '<span><img src="../res/ChatBox/emotion/Expression_16.png"  width="28" /></span>',
			'[酷]' : '<span><img src="../res/ChatBox/emotion/Expression_17.png"  width="28" /></span>',
			'[冷汗]' : '<span><img src="../res/ChatBox/emotion/Expression_18.png"  width="28" /></span>',
			'[抓狂]' : '<span><img src="../res/ChatBox/emotion/Expression_19.png"  width="28" /></span>',
			'[吐]' : '<span><img src="../res/ChatBox/emotion/Expression_20.png"  width="28" /></span>',
			'[偷笑]' : '<span><img src="../res/ChatBox/emotion/Expression_21.png"  width="28" /></span>',
			'[愉快]' : '<span><img src="../res/ChatBox/emotion/Expression_22.png"  width="28" /></span>',
			'[白眼]' : '<span><img src="../res/ChatBox/emotion/Expression_23.png"  width="28" /></span>',
			'[傲慢]' : '<span><img src="../res/ChatBox/emotion/Expression_24.png"  width="28" /></span>',
			'[饥饿]' : '<span><img src="../res/ChatBox/emotion/Expression_25.png"  width="28" /></span>',
			'[困]' : '<span><img src="../res/ChatBox/emotion/Expression_26.png"  width="28" /></span>',
			'[恐惧]' : '<span><img src="../res/ChatBox/emotion/Expression_27.png"  width="28" /></span>',
			'[流汗]' : '<span><img src="../res/ChatBox/emotion/Expression_28.png"  width="28" /></span>',
			'[憨笑]' : '<span><img src="../res/ChatBox/emotion/Expression_29.png"  width="28" /></span>',
			/*从这*/
			'[悠闲]' : '<span><img src="../res/ChatBox/emotion/Expression_30.png"  width="28" /></span>',
			'[奋斗]' : '<span><img src="../res/ChatBox/emotion/Expression_31.png"  width="28" /></span>',
			'[咒骂]' : '<span><img src="../res/ChatBox/emotion/Expression_32.png"  width="28" /></span>',
			'[疑问]' : '<span><img src="../res/ChatBox/emotion/Expression_33.png"  width="28" /></span>',
			'[嘘]' : '<span><img src="../res/ChatBox/emotion/Expression_34.png"  width="28" /></span>',
			'[晕]' : '<span><img src="../res/ChatBox/emotion/Expression_35.png"  width="28" /></span>',
			'[疯了]' : '<span><img src="../res/ChatBox/emotion/Expression_36.png"  width="28" /></span>',
			'[衰]' : '<span><img src="../res/ChatBox/emotion/Expression_37.png"  width="28" /></span>',
			'[骷髅]' : '<span><img src="../res/ChatBox/emotion/Expression_38.png"  width="28" /></span>',
			'[敲打]' : '<span><img src="../res/ChatBox/emotion/Expression_39.png"  width="28"/></span>',
			'[再见]' : '<span><img src="../res/ChatBox/emotion/Expression_40.png"  width="28"/></span>',
			'[擦汗]' : '<span><img src="../res/ChatBox/emotion/Expression_41.png"  width="28"/></span>',
			'[抠鼻]' : '<span><img src="../res/ChatBox/emotion/Expression_42.png"  width="28" /></span>',
			'[鼓掌]' : '<span><img src="../res/ChatBox/emotion/Expression_43.png"  width="28" /></span>',
			'[糗大了]' : '<span><img src="../res/ChatBox/emotion/Expression_44.png"  width="28" /></span>',
			'[坏笑]' : '<span><img src="../res/ChatBox/emotion/Expression_45.png"  width="28" /></span>',
			'[左哼哼]' : '<span><img src="../res/ChatBox/emotion/Expression_46.png"  width="28" /></span>',
			'[右哼哼]' : '<span><img src="../res/ChatBox/emotion/Expression_47.png"  width="28" /></span>',
			'[哈欠]' : '<span><img src="../res/ChatBox/emotion/Expression_48.png"  width="28" /></span>',
			'[鄙视]' : '<span><img src="../res/ChatBox/emotion/Expression_49.png"  width="28" /></span>',
			'[委屈]' : '<span><img src="../res/ChatBox/emotion/Expression_50.png"  width="28" /></span>',
			'[快哭了]' : '<span><img src="../res/ChatBox/emotion/Expression_51.png"  width="28" /></span>',
			'[阴险]' : '<span><img src="../res/ChatBox/emotion/Expression_52.png"  width="28" /></span>',
			'[亲亲]' : '<span><img src="../res/ChatBox/emotion/Expression_53.png"  width="28" /></span>',
			'[吓]' : '<span><img src="../res/ChatBox/emotion/Expression_54.png"  width="28" /></span>',
			'[可怜]' : '<span><img src="../res/ChatBox/emotion/Expression_55.png"  width="28" /></span>',
			'[菜刀]' : '<span><img src="../res/ChatBox/emotion/Expression_56.png"  width="28" /></span>',
			'[西瓜]' : '<span><img src="../res/ChatBox/emotion/Expression_57.png"  width="28" /></span>',
			'[啤酒]' : '<span><img src="../res/ChatBox/emotion/Expression_58.png"  width="28" /></span>',
			'[篮球]' : '<span><img src="../res/ChatBox/emotion/Expression_59.png"  width="28" /></span>',
			'[乒乓]' : '<span><img src="../res/ChatBox/emotion/Expression_60.png"  width="28" /></span>',
			'[咖啡]' : '<span><img src="../res/ChatBox/emotion/Expression_61.png"  width="28" /></span>',
			'[饭]' : '<span><img src="../res/ChatBox/emotion/Expression_62.png"  width="28" /></span>',
			'[猪头]' : '<span><img src="../res/ChatBox/emotion/Expression_63.png"  width="28" /></span>',
			'[玫瑰]' : '<span><img src="../res/ChatBox/emotion/Expression_64.png"  width="28" /></span>',
			'[凋谢]' : '<span><img src="../res/ChatBox/emotion/Expression_65.png"  width="28" /></span>',
			'[嘴唇]' : '<span><img src="../res/ChatBox/emotion/Expression_66.png"  width="28" /></span>',
			'[爱心]' : '<span><img src="../res/ChatBox/emotion/Expression_67.png"  width="28" /></span>',
			'[心碎]' : '<span><img src="../res/ChatBox/emotion/Expression_68.png"  width="28"/></span>',
			'[蛋糕]' : '<span><img src="../res/ChatBox/emotion/Expression_69.png"  width="28"/></span>',
			'[闪电]' : '<span><img src="../res/ChatBox/emotion/Expression_70.png"  width="28"/></span>',
			'[炸弹]' : '<span><img src="../res/ChatBox/emotion/Expression_71.png"  width="28" /></span>',
			'[刀]' : '<span><img src="../res/ChatBox/emotion/Expression_72.png"  width="28" /></span>',
			'[足球]' : '<span><img src="../res/ChatBox/emotion/Expression_73.png"  width="28" /></span>',
			'[瓢虫]' : '<span><img src="../res/ChatBox/emotion/Expression_74.png"  width="28" /></span>',
			'[便便]' : '<span><img src="../res/ChatBox/emotion/Expression_75.png"  width="28" /></span>',
			'[月亮]' : '<span><img src="../res/ChatBox/emotion/Expression_76.png"  width="28" /></span>',
			'[太阳]' : '<span><img src="../res/ChatBox/emotion/Expression_77.png"  width="28" /></span>',
			'[礼物]' : '<span><img src="../res/ChatBox/emotion/Expression_78.png"  width="28" /></span>',
			'[拥抱]' : '<span><img src="../res/ChatBox/emotion/Expression_79.png"  width="28" /></span>',
			'[强]' : '<span><img src="../res/ChatBox/emotion/Expression_80.png"  width="28" /></span>',
			'[弱]' : '<span><img src="../res/ChatBox/emotion/Expression_81.png"  width="28" /></span>',
			'[握手]' : '<span><img src="../res/ChatBox/emotion/Expression_82.png"  width="28" /></span>',
			'[胜利]' : '<span><img src="../res/ChatBox/emotion/Expression_83.png"  width="28" /></span>',
			'[抱拳]' : '<span><img src="../res/ChatBox/emotion/Expression_84.png"  width="28" /></span>',
			'[勾引]' : '<span><img src="../res/ChatBox/emotion/Expression_85.png"  width="28" /></span>',
			'[拳头]' : '<span><img src="../res/ChatBox/emotion/Expression_86.png"  width="28" /></span>',
			'[差劲]' : '<span><img src="../res/ChatBox/emotion/Expression_87.png"  width="28" /></span>',
			'[爱你]' : '<span><img src="../res/ChatBox/emotion/Expression_88.png"  width="28" /></span>',
			'[NO]' : '<span><img src="../res/ChatBox/emotion/Expression_89.png"  width="28" /></span>',
			'[OK]' : '<span><img src="../res/ChatBox/emotion/Expression_90.png"  width="28" /></span>',
			'[爱情]' : '<span><img src="../res/ChatBox/emotion/Expression_91.png"  width="28" /></span>',
			'[飞吻]' : '<span><img src="../res/ChatBox/emotion/Expression_92.png"  width="28" /></span>',
			'[跳跳]' : '<span><img src="../res/ChatBox/emotion/Expression_93.png"  width="28" /></span>',
			'[发抖]' : '<span><img src="../res/ChatBox/emotion/Expression_94.png"  width="28" /></span>',
			'[怄火]' : '<span><img src="../res/ChatBox/emotion/Expression_95.png"  width="28" /></span>',
			'[转圈]' : '<span><img src="../res/ChatBox/emotion/Expression_96.png"  width="28" /></span>',
			'[磕头]' : '<span><img src="../res/ChatBox/emotion/Expression_97.png"  width="28"/></span>',
			'[回头]' : '<span><img src="../res/ChatBox/emotion/Expression_98.png"  width="28"/></span>',
			'[跳绳]' : '<span><img src="../res/ChatBox/emotion/Expression_99.png"  width="28"/></span>',
			'[投降]' : '<span><img src="../res/ChatBox/emotion/Expression_100.png"  width="28" /></span>',
			'[激动]' : '<span><img src="../res/ChatBox/emotion/Expression_101.png"  width="28" /></span>',
			'[街舞]' : '<span><img src="../res/ChatBox/emotion/Expression_102.png"  width="28" /></span>',
			'[献吻]' : '<span><img src="../res/ChatBox/emotion/Expression_103.png"  width="28" /></span>',
			'[左太极]' : '<span><img src="../res/ChatBox/emotion/Expression_104.png"  width="28" /></span>',
			'[右太极]' : '<span><img src="../res/ChatBox/emotion/Expression_105.png"  width="28" /></span>',
			'[哈哈]' : '<span><img src="../res/ChatBox/emotion/Expression_106.png"  width="28" /></span>'

		};
		//打开图像
		function openImage(path) {
			var imageBrowser = api.require('imageBrowser');
			imageBrowser.openImages({
				imageUrls : [path]
			});
		}

		//时间差计算
		function sj(sj) {
			var nowt = new Date().getTime();
			var a = new Date(parseInt(sj));
			var b = new Date(parseInt(nowt));
			var date1 = Date.parse(format(a, 4));
			var date2 = Date.parse(format(b, 4));
			var xxsj = Math.ceil((date2 - date1) / (60 * 1000))
			var tian1 = new Date(date1).getDate()
			var tian2 = new Date(date2).getDate()
		
			if (xxsj <= 1 && xxsj >= 0) {
				return "就刚才";
			} else if (xxsj <= 10 && xxsj > 1) {
				return xxsj + "分钟前";
			} else if (xxsj <= 60 && xxsj > 10) {
				return format(a, 1);
			} else if (xxsj <= 2879 && xxsj > 60) {
				if(tian2 - tian1 == 1){
					return '昨天' + format(a, 1);
				}else{
					return format(a, 1);
				}
			} else if (xxsj <= 10080 && xxsj > 2879) {
				return format(a, 6);
			} else if (xxsj > 10080) {
				return format(a, 3);
			} else {
				return format(a, 3);
			}
		}

		//json格式转换
		function transExtra(arg) {
			var result = '';
			try {
				result = eval('(' + arg + ')');
			} catch (e) {
				result = arg.slice(1, -1);
			} finally {
			}
			return result;
		}

		//格式化时间
		function format(now, type) {
			var show_day = new Array('星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六');
			var year = now.getFullYear().toString();
			var month = (now.getMonth() + 1).toString();
			var day = (now.getDate()).toString();
			var tian = now.getDay().toString();
			var hour = (now.getHours()).toString();
			var minute = (now.getMinutes()).toString();
			var second = (now.getSeconds()).toString();
			if (hour.length == 1) {
				hour = "0" + hour;
			}
			if (minute.length == 1) {
				minute = "0" + minute;
			}
			if (second.length == 1) {
				second = "0" + second;
			}
			if (type == 1) {
				var dateTime = hour + ":" + minute;
			} else if (type == 2) {
				var dateTime = show_day[tian] + " " + hour + ":" + minute
			} else if (type == 3) {
				var dateTime = year + "-" + month + "-" + day
			} else if (type == 4) {
				var dateTime = year + "/" + month + "/" + day + " " + hour + ":" + minute + ":" + second;
			} else if (type == 5) {
				var dateTime = year + "年" + month + "月" + day + " " + hour + ":" + minute + ":" + second;
			} else if (type == 6) {
				var dateTime = month + "月" + day + " " + hour + ":" + minute + ":" + second;
			} else if (type == 7) {
				var dateTime = show_day[tian];
			}
			return dateTime;
		}
			function getSubStr (str){
			if(str.length<=15){
				return str;
			}
	  var subStr1 = str.substr(0,10);
	  var subStr2 = str.substr(str.length-5,5);
	  var subStr = subStr1 + "..." + subStr2 ;
	  return subStr;
	}
	function checktype(type){
	var type_arr = ['ara','gif','html','jpg','png','ppt','txt','word','xsl','zip'];
	index = type_arr.indexOf(type);
	if(index==-1){
		return 'undefined';
	}
	return type;
	}
	function openfile(url) {
    var obj =url.lastIndexOf("/");
    var filename = url.substr(obj+1);
		if(url){
			var downloadManager = api.require('downloadManager');
			downloadManager.enqueue({
		    url: url,
		    savePath: 'fs://file/'+filename,
		    cache: true,
		    allowResume: true,
		    title: '文件',
		    networkTypes: 'all'
		}, function(ret, err) {
			downloadManager.openDownloadedFile({
			    id: ret.id
			}, function(ret1, err1) {
			    if (ret.status) {
			    } else {
						api.toast({
							msg : '打开文件失败',
							duration : 1000,
							location : 'center'
						});
			    }
			});
		});

		}


	}

	</script>
</html>
